IT[X]
[ class tree: IT[X] ] [ index: IT[X] ] [ all elements ]

Class: HTML_Template_ITX

Source Location: /HTML_Template_IT-1.1.2/ITX.php

Class Overview

HTML_Template_IT
   |
   --HTML_Template_ITX

Integrated Template Extension - ITX


Author(s):

Version:

  • $Id: ITX.php,v 1.13 2005/10/28 11:00:33 dufuz Exp $

Variables

Methods


Inherited Variables

Inherited Methods

Class: HTML_Template_IT

HTML_Template_IT::HTML_Template_IT()
Builds some complex regular expressions and optinally sets the file root directory.
HTML_Template_IT::buildBlockvariablelist()
Build a list of all variables within of a block
HTML_Template_IT::errorMessage()
Return a textual error message for a IT error code
HTML_Template_IT::findBlocks()
Recusively builds a list of all blocks within the template.
HTML_Template_IT::free()
Clears all datafields of the object.
HTML_Template_IT::get()
Returns a block with all replacements done.
HTML_Template_IT::getFile()
Reads a file from disk and returns its content.
HTML_Template_IT::getGlobalvariables()
Returns a list of all global variables
HTML_Template_IT::init()
Clears all datafields of the object and rebuild the internal blocklist
HTML_Template_IT::loadTemplatefile()
Reads a template file from the disk.
HTML_Template_IT::parse()
Parses the given block.
HTML_Template_IT::parseCurrentBlock()
Parses the current block
HTML_Template_IT::setCurrentBlock()
Sets the name of the current block that is the block where variables are added.
HTML_Template_IT::setOption()
Sets the option for the template class
HTML_Template_IT::setOptions()
Sets the options for the template class
HTML_Template_IT::setRoot()
Sets the file root. The file root gets prefixed to all filenames passed to the object.
HTML_Template_IT::setTemplate()
Sets the template.
HTML_Template_IT::setVariable()
Sets a variable value.
HTML_Template_IT::show()
Print a certain block with all replacements done.
HTML_Template_IT::touchBlock()
Preserves an empty block even if removeEmptyBlocks is true.

Class Details

[line 42]
Integrated Template Extension - ITX

With this class you get the full power of the phplib template class. You may have one file with blocks in it but you have as well one main file and multiple files one for each block. This is quite usefull when you have user configurable websites. Using blocks not in the main template allows you to modify some parts of your layout easily.

Note that you can replace an existing block and add new blocks at runtime. Adding new blocks means changing a variable placeholder to a block.

  • Author: Ulf Wendel <uw@netuse.de>
  • Version: $Id: ITX.php,v 1.13 2005/10/28 11:00:33 dufuz Exp $
  • Access: public


[ Top ]


Class Variables

$callback = array()

[line 108]

List of callback functions specified by the user.

Type:   array


[ Top ]

$checkblocknameRegExp =  ''

[line 72]

RegExp used to test for a valid blockname.

Type:   string


[ Top ]

$functionnameRegExp =  '[_a-zA-Z]+[A-Za-z_0-9]*'

[line 84]

Functionname RegExp.

Type:   string


[ Top ]

$functionPrefix =  'func_'

[line 78]

Functionnameprefix used when searching function calls in the template.

Type:   string


[ Top ]

$functionRegExp =  ''

[line 94]

RegExp used to grep function calls in the template.

The variable gets set by the constructor.


Type:   string


[ Top ]

$functions = array()

[line 101]

List of functions found in the template.

Type:   array


[ Top ]

$haltOnWarning =  false

[line 66]

Call die() on warning?

Type:   boolean


[ Top ]

$printWarning =  false

[line 58]

Print warnings?

Type:   array


[ Top ]

$warn = array()

[line 50]

Array with all warnings.

Type:   array


[ Top ]



Method Detail

HTML_Template_ITX (Constructor)   [line 119]

HTML_Template_ITX HTML_Template_ITX( [ $root = ''])

Builds some complex regexps and calls the constructor of the parent class.

Make sure that you call this constructor if you derive your own template class from this one.


Parameters:

   $root   — 

[ Top ]

addBlock   [line 248]

boolean addBlock( string $placeholder, string $blockname, string $template)

Adds a block to the template changing a variable placeholder to a block placeholder.

Add means "replace a variable placeholder by a new block". This is different to PHPLibs templates. The function loads a block, creates a handle for it and assigns it to a certain variable placeholder. To to the same with PHPLibs templates you would call set_file() to create the handle and parse() to assign the parsed block to a variable. By this PHPLibs templates assume that you tend to assign a block to more than one one placeholder. To assign a parsed block to more than only the placeholder you specify in this function you have to use a combination of getBlock() and setVariable().

As no updates to cached data is necessary addBlock() and addBlockfile() are rather "cheap" meaning quick operations.

The block content must not start with <!-- BEGIN blockname --> and end with <!-- END blockname --> this would cause overhead and produce an error.


Parameters:

string   $placeholder   —  Name of the variable placeholder, the name must be unique within the template.
string   $blockname   —  Name of the block to be added
string   $template   —  Content of the block

[ Top ]

addBlockfile   [line 332]

void addBlockfile( string $placeholder, string $blockname, string $filename)

Adds a block taken from a file to the template changing a variable placeholder to a block placeholder.

Parameters:

string   $placeholder   —  Name of the variable placeholder to be converted
string   $blockname   —  Name of the block to be added
string   $filename   —  File that contains the block

[ Top ]

blockExists   [line 571]

boolean blockExists( string $blockname)

Checks wheter a block exists.

Parameters:

string   $blockname   — 

[ Top ]

BlockvariableExists   [line 607]

boolean BlockvariableExists( string $block, string $variable)

Checks wheter a block variable exists.

Parameters:

string   $block   —  Blockname
string   $variable   —  Variablename

[ Top ]

buildFunctionlist   [line 615]

void buildFunctionlist( )

Builds a functionlist from the template.

[ Top ]

deleteFromBlockvariablelist   [line 707]

void deleteFromBlockvariablelist( string $block, mixed $variables)

Deletes one or many variables from the block variable list.

Parameters:

string   $block   —  Blockname
mixed   $variables   —  Name of one variable or array of variables ( array ( name => true ) ) to be stripped.

[ Top ]

findPlaceholderBlocks   [line 762]

array findPlaceholderBlocks( string $variable)

Returns an array of blocknames where the given variable placeholder is used.
  • Return: parents[0..n] = blockname

Parameters:

string   $variable   —  Variable placeholder

[ Top ]

getBlocklist   [line 553]

array getBlocklist( )

Returns a list of blocknames in the template.

[ Top ]

getBlockvariables   [line 584]

array getBlockvariables( string $block)

Returns a list of variables of a block.

Parameters:

string   $block   —  Blockname

[ Top ]

getFunctioncalls   [line 430]

array getFunctioncalls( )

Returns a list of all function calls in the current template.
  • Access: public

[ Top ]

getValue   [line 657]

void getValue( $code, $delimiter)


Parameters:

   $code   — 
   $delimiter   — 

[ Top ]

init   [line 129]

void init( )


Overrides HTML_Template_IT::init() (Clears all datafields of the object and rebuild the internal blocklist)
[ Top ]

performCallback   [line 399]

void performCallback( )

Checks the list of function calls in the template and calls their callback function.
  • Access: public

[ Top ]

placeholderExists   [line 351]

string placeholderExists( string $placeholder, [string $block = ''])

Returns the name of the (first) block that contains the specified placeholder.
  • Return: Name of the (first) block that contains the specified placeholder. If the placeholder was not found or an error occured an empty string is returned.
  • Throws: IT_Error
  • Access: public

Parameters:

string   $placeholder   —  Name of the placeholder you're searching
string   $block   —  Name of the block to scan. If left out (default) all blocks are scanned.

[ Top ]

removeBlockData   [line 529]

void removeBlockData( string $block)

Recursively removes all data assiciated with a block, including all inner blocks

Parameters:

string   $block   —  block to be removed

[ Top ]

replaceBlock   [line 165]

boolean replaceBlock( string $block, string $template, [boolean $keep_content = false])

Replaces an existing block with new content.

This function will replace a block of the template and all blocks contained in the replaced block and add a new block insted, means you can dynamically change your template.

Note that changing the template structure violates one of the IT[X] development goals. I've tried to write a simple to use template engine supporting blocks. In contrast to other systems IT[X] analyses the way you've nested blocks and knows which block belongs into another block. The nesting information helps to make the API short and simple. Replacing blocks does not only mean that IT[X] has to update the nesting information (relatively time consumpting task) but you have to make sure that you do not get confused due to the template change itself.


Parameters:

string   $block   —  Blockname
string   $template   —  Blockcontent
boolean   $keep_content   —  true if the new block inherits the content of the old block

[ Top ]

replaceBlockfile   [line 212]

void replaceBlockfile( string $block, string $filename, [boolean $keep_content = false])

Replaces an existing block with new content from a file.

Parameters:

string   $block   —  Blockname
string   $filename   —  Name of the file that contains the blockcontent
boolean   $keep_content   —  true if the new block inherits the content of the old block

[ Top ]

setCallbackFunction   [line 491]

boolean setCallbackFunction( string $tplfunction, string $callbackfunction, [string $callbackobject = ''])

Sets a callback function.

IT[X] templates (note the X) can contain simple function calls. "function call" means that the editor of the template can add special placeholder to the template like 'func_h1("embedded in h1")'. IT[X] will grab this function calls and allow you to define a callback function for them.

This is an absolutely evil feature. If your application makes heavy use of such callbacks and you're even implementing if-then etc. on the level of a template engine you're reiventing the wheel... - that's actually how PHP came into life. Anyway, sometimes it's handy.

Consider also using XML/XSLT or native PHP. And please do not push IT[X] any further into this direction of adding logics to the template engine.

For those of you ready for the X in IT[X]:

<?php ... function h_one($args) { return sprintf('<h1>%s</h1>', $args[0]); }

... $itx = new HTML_Template_ITX( ... ); ... $itx->setCallbackFunction('h1', 'h_one'); $itx->performCallback(); ?>

template: func_h1('H1 Headline');

  • Return: False on failure.
  • Throws: IT_Error
  • Access: public

Parameters:

string   $tplfunction   —  Function name in the template
string   $callbackfunction   —  Name of the callback function
string   $callbackobject   —  Name of the callback object

[ Top ]

setCallbackFuntiontable   [line 519]

void setCallbackFuntiontable( array $functions)

Sets the Callback function lookup table
  • Access: public

Parameters:

array   $functions   —  function table array[templatefunction] = array( "function" => userfunction, "object" => userobject )

[ Top ]

setFunctioncontent   [line 442]

void setFunctioncontent( int $functionID, string $replacement)

Replaces a function call with the given replacement.
  • Deprec:

Parameters:

int   $functionID   —  Function ID
string   $replacement   —  Replacement

[ Top ]

updateBlockvariablelist   [line 726]

void updateBlockvariablelist( string $block)

Updates the variable list of a block.

Parameters:

string   $block   —  Blockname

[ Top ]

warning   [line 789]

void warning( string $message, [string $file = ''], [int $line = 0])

Handles warnings, saves them to $warn and prints them or calls die() depending on the flags

Parameters:

string   $message   —  Warning
string   $file   —  File where the warning occured
int   $line   —  Linenumber where the warning occured

[ Top ]


Documentation generated on Mon, 11 Mar 2019 14:11:06 -0400 by phpDocumentor 1.4.4. PEAR Logo Copyright © PHP Group 2004.